#include <iostream>
#include <stdlib.h>

typedef int ElemType;
typedef struct LNode{
    ElemType data;
    struct LNode *next;
}LNode, *LinkList;

void EnQueue(LinkList front,LinkList &rear, ElemType value)
{
    LinkList pnew;
    if(rear->next==front)
    {
        //队列满申请一个结点空间
        pnew=(LinkList)malloc(sizeof(LNode));
        rear->data=value;
        rear->next=pnew;
        pnew->next=front;
        rear=pnew;
    }
    //如果队列不满，直接放值
    else
    {
        rear->data=value;
        rear=rear->next;
    }
}

void DeQueue(LinkList &front,LinkList rear)
{
    if(front==rear)
    {
        printf("CircleQueue is empty\n");
    } else{
        printf("DeQueue is %d\n",front->data);
        front=front->next;
    }
}

void CircleQueue(LinkList &front, LinkList &rear)
{
    //队头和队尾指向同一个结点，这时队列即使空的也是满的
    front=(LinkList)malloc(sizeof(LNode));
    rear=front;
    rear->next=front;
    //入队
    EnQueue(front, rear, 3);
    EnQueue(front, rear, 4);
    //出队
    DeQueue(front, rear);
    DeQueue(front, rear);
    DeQueue(front, rear);
}
//循环链表
int main()
{
    LinkList front,rear;
    CircleQueue(front,rear);
    return 0;
}
